<style lang="less">
@import '../../../assets/style/yhqx_list.less';
</style>
<template>
	<mxq-router-layout>
		<div class="qxyh_list yinhuan_list">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					<span>隐患查看</span>
				</div>
				<div slot="headerRight" v-show="xzbtn">
					<span>新增</span>
				</div>
				<div slot="headerRight" v-show="!xzbtn">
					<i class="iconfont icon-shouye"/>
					<!--<van-icon class="home" name="home"/>-->
				</div>
			</Head>
			<GanTaList
				v-if="yhLists && yhLists.length >= 0"
				:gantaList="yhLists"
				:picUrlLeft="picUrlLeft"
				@clickList="clickList($event)">
				<template slot="titles" slot-scope="item">
					<span>
						<img
							:src="picUrlRight"
							class="arrow"
							alt="890"
						>
					</span>
				</template>
			</GanTaList>
			<!--无数据时-->
			<div v-if="yhLists  && yhLists.length == 0" class="cont_box">
				<img class="pic_zanwu" src="../../../assets/img/changguixunshi/icon_zanwu.png" alt="">
				<p class="text_zanwu">暂无历史隐患哦！！！</p>
			</div>
			<!-- 弹出层 开始 -->
			<div class="pop_up">
				<van-popup v-model="show">
					<div class="arrow-up"></div><!--向上的三角-->
					<van-cell-group v-for="(item,index) in xinzengData" :key="index">
						<van-cell :title="item.YH_NAME" class="icon" @click="to(item)" />
					</van-cell-group>
				</van-popup>
			</div>
			<!-- 弹出层 结束 -->
			<!--<van-button size="large" type="primary" class="btn_sure" @click="goNext">确定</van-button>-->
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '@/components/head';
import GanTaList from '../../../components/ganta-list';
import { callData } from '../../../axios/axios';
import IconYH from '../../../assets/img/icon_yh.png';
import IconJT from '../../../assets/img/changguixunshi/icon_jt.png';
import {
	Cell,
	Icon,
	CellGroup,
	Button,
	Popup
} from 'vant';

export default {
    name: 'news',
    components: {
		Head,
		GanTaList,
		[Cell.name]: Cell,
		[Icon.name]: Icon,
		[CellGroup.name]: CellGroup,
		[Button.name]: Button,
		[Popup.name]: Popup
	},
	data() {
		return {
			yhLists:[],
			picUrlLeft: IconYH,
			picUrlRight: IconJT,
			show: false,
			xinzengData:[],
			xzbtn:true
		}
	},
	mounted(){
		this.getListData()
		if(this.$route.query.towerStatus == 2 || this.$route.query.towerStatus == 0){
			this.xzbtn = false;
		}
	},
	methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			if(this.xzbtn){
				this.show=true
				this.xinzengList();
			}else{
				let query = {}
				this.$router.push({
					name:'index',
					query: query
				})
			}
		},
		//点击新增时返回新增列表
		xinzengList(){
			var params = {
				pid:0
			}
			callData('/accountServer/CmYhLb/findCmYhLb', 'get', params).then(data => {
				this.xinzengData = data.data;
			})
		},
		// 隐患列表点击事件
		clickList(e){
			this.$router.push({
				path:'/cgxs_yinhuanDetail',
				query: {
					xsId: this.$route.query.xsId,
					page: this.$route.query.page,
					size: this.$route.query.size,
					towerId:this.$route.query.towerId,
					towerTaskId:this.$route.query.towerTaskId,
					taskId :this.$route.query.taskId,
					lineId:this.$route.query.lineId,
					lineTowerId :this.$route.query.lineTowerId,
					yhId :e.data.ID,
					yhLb:e.data.YH_LB,
					defectType:e.data.DEFECT_TYPE,
					taskStatus:this.$route.query.taskStatus,
					towerStatus: this.$route.query.towerStatus,
					name:'cgxs_yinhuanDetail'
				}
			})
		},
		// 确认点击事件
		goNext(){
			let query = {}
			this.$router.push({
				name:'cgxs_allowPhotos',
				query: query
			})
		},
		to(item) {
			let query = {
				yhId:item.ID,
				cmYhName:item.YH_NAME,
				towerId:this.$route.query.towerId,
				lineId:this.$route.query.lineId,
				lineName:this.$route.query.lineName,
				towerName:this.$route.query.towerName,
				taskId :this.$route.query.taskId,
				lineTowerId :this.$route.query.lineTowerId,
				towerTaskId:this.$route.query.towerTaskId,
				xsId: this.$route.query.xsId,
				page: this.$route.query.page,
				size: this.$route.query.size,
			}
			this.$router.push({
				name:'cgxs_yinhuanXinzheng',
				query: query
			})
		},
		getListData() {
			var _this = this;
			var towerId  = _this.$route.query.towerId;
			var params ={
				towerId:_this.$route.query.towerId,
				towerTaskId:_this.$route.query.towerTaskId,
				taskId:_this.$route.query.taskId
			}
			callData('/accountServer/CmYhLb/appFindYh', 'get', params).then(data => {
				var listArr = data.data;
				listArr.forEach((item,index) => {
					item.textName = item.YH_NAME;
					// 状态判断
					if (item.DEFECT_TYPE == 0) {
						item.statusName = '已复核';
						item.cname="btn_status2";
					}else if (item.DEFECT_TYPE == 1) {
						item.statusName = '已消缺';
						item.cname="btn_status2";
					}else if (item.DEFECT_TYPE == 2) {
						item.statusName = '新增';
						item.cname="btn_status";
					}else if (item.DEFECT_TYPE == '-1') {
						item.statusName = '待处理';
						item.cname="btn_status1";
					}
					
				})
				this.yhLists = listArr;
			})
		}
		
	}
}
</script>